import rx.Observable;
import rx.Subscription;

import java.util.Random;

/**
 * Created by codeczx on 2017/2/21.
 */
public class AdvancedErrorHandleTest {

    void testOnErrorResumeNext(){
        Observable<Integer> values = Observable.create(o->{
            o.onNext(1);
            o.onNext(2);
            o.onError(new Exception("Oops"));
        });
        values.onErrorResumeNext(Observable.just(Integer.MAX_VALUE))
                .subscribe(new PrintSubscriber("onErrorResumeNext"));
    }

    void testRetry(){
        Random random = new Random();
        Observable<Integer> values = Observable.create(o->{
            o.onNext(random.nextInt()%20);
            o.onNext(random.nextInt()%20);
            o.onError(new Throwable("throwable from testRetry"));
        });
        values.retry(3)
                .subscribe(new PrintSubscriber("testRetry"));
    }

    public static void main(String[] args) {
        AdvancedErrorHandleTest aeht = new AdvancedErrorHandleTest();
//        aeht.testOnErrorResumeNext();
        aeht.testRetry();
    }
}
